<?php

require_once 'common/conn.php';
$result = array();

if (isset($_GET['usercode'])) {
    $usercode = $_GET['usercode'];
}

if (isset($_GET['login'])) {
    $login = $_GET['login'];
}

if (isset($usercode) && isset($login)) {
    $usercode = trim($usercode);
    $login = trim($login);
    if ($login == "login") {
        $login = 1;
    } else if ($login == "logout") {
        $login = -1;
    }

    $sql = "INSERT INTO t_login_record(usercode,logintime,duration,type) VALUES('" . $usercode . "',now(),0," . $login . ")";

    $db = new DBC();

    if ($db->execute($sql)) {
        $result['errorNo'] = "0";
    } else {
        $result['errorNo'] = "1";
    }
} else {
    $result['errorNo'] = "1";
}

echo json_encode($result);
?>
